package com.xuxin.nantai.activity;

import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.xuxin.nantai.R;
import com.xuxin.nantai.activity.cai.ChaiActivity;
import com.xuxin.nantai.activity.chou.SelectActivity;
import com.xuxin.nantai.activity.hang.HangActivity;
import com.xuxin.nantai.activity.pack.PackActivity;
import com.xuxin.nantai.activity.quan.CompleteActivity;
import com.xuxin.nantai.base.BaseActivity;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

import butterknife.BindView;

public class MainActivity extends BaseActivity {
    @BindView(R.id.title_left)
    ImageView title_left;
    @BindView(R.id.title_right)
    ImageView title_right;
    @BindView(R.id.title_name)
    TextView title_name;

    @BindView(R.id.smart_refresh)
    SmartRefreshLayout smart_refresh;
    @BindView(R.id.smart_recycle)
    RecyclerView smart_recycle;

    @Override
    public void setContentView() {
        setContentView(R.layout.activity_smart);
    }

    @Override
    public void initView() {
        title_name.setText("南泰质检");
        title_left.setVisibility(View.INVISIBLE);
        smart_refresh.setEnableRefresh(false);
        smart_refresh.setEnableLoadMore(false);
        smart_recycle.setLayoutManager(new LinearLayoutManager(this));
        smart_recycle.setItemViewCacheSize(10);
        smart_recycle.setNestedScrollingEnabled(false);
        MainAdapter myAdapter = new MainAdapter();
        smart_recycle.setAdapter(myAdapter);
        myAdapter.setOnItemClickListener((adapter, view, position) -> {
            switch (position) {
                case 0://绗缝巡检
                    ActivityUtils.startActivity(HangActivity.class);
                    break;
                case 1://裁剪巡检
                    ActivityUtils.startActivity(ChaiActivity.class);
                    break;
                case 2://缝制全检
                    ActivityUtils.startActivity(CompleteActivity.class);
                    break;
                case 3://缝制抽检
                    ActivityUtils.startActivity(SelectActivity.class);
                    break;
                case 4://包装巡检
                    ActivityUtils.startActivity(PackActivity.class);
                    break;
            }
        });
    }

    @Override
    public void initData() {
    }

    @Override
    public void onComplete() {

    }

    @Override
    public void onClick(View view) {
    }

    private long exitTime = 0;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                ToastUtils.showShort("再按一次退出");
                exitTime = System.currentTimeMillis();
            } else {
                finish();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    private static class MainAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

        private MainAdapter() {
            super(R.layout.item_main);
            ArrayList<String> list = new ArrayList<String>();
            list.add("绗缝巡检");
            list.add("裁剪巡检");
            list.add("缝制全检");
            list.add("缝制抽检");
            list.add("包装巡检");
            setList(list);
        }

        @Override
        protected void convert(@NotNull BaseViewHolder holder, String item) {
            holder.setText(R.id.item_main_name, item);
        }
    }
}